import csv
import pytest

# 被测函数
def plus(num1, num2):
    return num1 + num2


#从csv文件读取测试数据
def read_data():
    with open("data.csv", "r") as f:
        reader = csv.reader(f)
        next(reader)  # 跳过首行
        result = []
        for item in reader:
            dict = {"num1": int(item[0]),
                    "num2": int(item[1]),
                    "result": int(item[2])
                    }
            result.append(dict)
    return result


@pytest.mark.parametrize("dict", read_data())
def test_plus(dict):
    assert plus(dict["num1"], dict["num2"]) == dict["result"]

if __name__ == '__main__':
    pytest.main(['-s', 'mengfeiyuan.py'])